<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let arr1 = [1, 2, 3, 4, 5]
    let arr2 = [6, 7, 8, 9, 10]
    console.log(...arr1) // 展开一个数组
    let arr3 = [...arr1, ...arr2] // 连接数组
    console.log(arr3)
    // 在函数种使用
    function sun(...numbers) {
      return numbers.reduce((preValue, currenValue) => {
        return preValue + currenValue
      })
    }
    console.log(sun(1, 2, 3, 4))

    // 构造字面量对象时使用展开语法
    let person = { name: 'tom', age: '18' }
    let person2 = { ...person } // 一级是深拷贝，大于一级是浅拷贝
    // console.log(...person) // 报错，展开运算符不能展开对象
    person.name = 'jerry'
    console.log(person2)

    // 合并
    let person3 = { ...person, name: 'jack', address: '中国' }
    console.log('person3: ', person3);
  </script>
</body>

</html>